/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.rs.controller;

import java.util.Collection;
import java.util.List;

import com.xy.biz.rs.domain.constants.ManufactureRecordModifyApplyConstants;
import com.xy.biz.rs.domain.req.UpdateManufactureRecordModifyApplyRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xy.lang.domain.Page;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.SaveChecks;
import com.xy.lang.validation.UpdateChecks;
import com.xy.lang.validation.annotation.Validatable;

import com.xy.biz.rs.domain.resp.GetManufactureRecordModifyApplyResponse;
import com.xy.biz.rs.domain.req.GetManufactureRecordModifyApplyRequest;
import com.xy.biz.rs.domain.req.ListManufactureRecordModifyApplyRequest;
import com.xy.biz.rs.domain.req.SaveManufactureRecordModifyApplyRequest;
import com.xy.biz.rs.domain.query.ManufactureRecordModifyApplyQuery;
import com.xy.biz.rs.domain.converter.ManufactureRecordModifyApplyConverter;
import com.xy.biz.rs.client.ManufactureRecordModifyApplyClient;
import com.xy.biz.rs.service.ManufactureRecordModifyApplyService;

/**
 *
 *
 * @author wwj
 * @date 2021-4-16
 */
@Api(tags = "生产记录修改申请")
@Slf4j
@RestController
@RequestMapping("/api/rs/manufacture/record/modify/apply")
public class ManufactureRecordModifyApplyController implements ManufactureRecordModifyApplyClient {

	@Autowired
	private ManufactureRecordModifyApplyService manufactureRecordModifyApplyService;

	@ApiOperation(value = "保存")
	@Validatable(groups = {SaveChecks.class})
	@PostMapping(value = "/save")
	public Result<?> saveManufactureRecordModifyApply(@RequestBody SaveManufactureRecordModifyApplyRequest request) {
		return manufactureRecordModifyApplyService.saveManufactureRecordModifyApply(ManufactureRecordModifyApplyConverter.toBO(request));
	}

	@Validatable(groups = {SaveChecks.class})
	@PostMapping(value = "/save_all")
	public Result<?> saveAllManufactureRecordModifyApply(@RequestBody Collection<SaveManufactureRecordModifyApplyRequest> collection) {
		manufactureRecordModifyApplyService.saveAllManufactureRecordModifyApply(ManufactureRecordModifyApplyConverter.toBO(collection));
		return Result.success();
	}

	@Validatable(groups = {UpdateChecks.class})
	@PostMapping(value = "/update")
	public Result<?> updateManufactureRecordModifyApply(@RequestBody SaveManufactureRecordModifyApplyRequest request) {
		manufactureRecordModifyApplyService.updateManufactureRecordModifyApply(ManufactureRecordModifyApplyConverter.toBO(request));
		return Result.success();
	}

	@ApiOperation(value = "更新状态：0-申请修改，1-同意修改")
	@Validatable(groups = {UpdateChecks.class})
	@PostMapping(value = "/update_status")
	public Result<?> updateManufactureRecordModifyApplyStatus(@RequestBody UpdateManufactureRecordModifyApplyRequest request) {
		return manufactureRecordModifyApplyService.updateManufactureRecordModifyApply(ManufactureRecordModifyApplyConverter.toBO(request));
	}

	@Validatable
	@PostMapping(value = "/delete")
	public Result<?> deleteManufactureRecordModifyApply(@RequestBody GetManufactureRecordModifyApplyRequest request) {
		manufactureRecordModifyApplyService.deleteManufactureRecordModifyApply(request.getManufactureRecordModifyApplyId());
		return Result.success();
	}

	@Validatable
	@PostMapping(value = "/get")
	@Override
	public Result<GetManufactureRecordModifyApplyResponse> getManufactureRecordModifyApply(@RequestBody GetManufactureRecordModifyApplyRequest request) {
		return Result.success(ManufactureRecordModifyApplyConverter.toResponse(manufactureRecordModifyApplyService.getManufactureRecordModifyApply(request.getManufactureRecordModifyApplyId())));
	}

	@PostMapping(value = "/list_by_ids")
	@Override
	public Result<List<GetManufactureRecordModifyApplyResponse>> listManufactureRecordModifyApplyById(@RequestBody Collection<Long> collection) {
		return Result.success(ManufactureRecordModifyApplyConverter.toResponse(manufactureRecordModifyApplyService.listManufactureRecordModifyApplyById(collection)));
	}

	@PostMapping(value = "/list")
	@Override
	public Result<List<GetManufactureRecordModifyApplyResponse>> listManufactureRecordModifyApply(@RequestBody ListManufactureRecordModifyApplyRequest request) {
		return Result.success(ManufactureRecordModifyApplyConverter.toResponse(manufactureRecordModifyApplyService.listManufactureRecordModifyApply(ManufactureRecordModifyApplyConverter.toQuery(request))));
	}

	@PostMapping(value = "/count")
	@Override
	public Result<Integer> countManufactureRecordModifyApply(@RequestBody ListManufactureRecordModifyApplyRequest request) {
		return Result.success(manufactureRecordModifyApplyService.countManufactureRecordModifyApply(ManufactureRecordModifyApplyConverter.toQuery(request)));
	}

	@ApiOperation(value = "分页")
	@PostMapping(value = "/page")
	@Override
	public Result<Page<GetManufactureRecordModifyApplyResponse>> pageManufactureRecordModifyApply(@RequestBody ListManufactureRecordModifyApplyRequest request) {
		ManufactureRecordModifyApplyQuery query = ManufactureRecordModifyApplyConverter.toQuery(request);
		query.setStatus(ManufactureRecordModifyApplyConstants.STATUS_UNMOTIFY);
		List<GetManufactureRecordModifyApplyResponse> list = ManufactureRecordModifyApplyConverter.toResponse(manufactureRecordModifyApplyService.listManufactureRecordModifyApply(query));
		int count = manufactureRecordModifyApplyService.countManufactureRecordModifyApply(query);
		return Result.success(new Page<>(list, count));
	}

}
